//package com.moduleSys.config.mybatis;
//
///**
// * Created by czw on 2017/7/1 0001.
// */
//import com.alibaba.druid.pool.DruidDataSourceFactory;
//import com.moduleSys.config.druid.DruidDataSourceBuilder;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternResolver;
//
//import javax.sql.DataSource;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
//@Configuration
//@MapperScan("com.moduleSys.mapper")
//public class MyBatisConfig {
//    private static final Logger logger = LoggerFactory.getLogger(MyBatisConfig.class);
///*    @Value("${spring.datasource.url}")
//    String dbUrl;
//    @Value("${spring.datasource.username}")
//    String userName;
//    @Value("${spring.datasource.password}")
//    String password;
//
//    @Value("${spring.datasource.driver-class-name}")
//    String driverClassName;
//
//    @Value("${spring.datasource.maxWait}")
//    String maxWait;*/
//
//    @Autowired
//    private DruidDataSourceBuilder druidDataSourceBuilder;
//
//    private static String MYBATIS_CONFIG = "mybatis_config.xml";
//    private static String MAPPER_PATH = "com/moduleSys/mapper/*.xml";
//
//    @Bean
//    public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//        //设置mybatis configuration 扫描路径
//        sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(MYBATIS_CONFIG));
//        //添加mapper 扫描路径
//        PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
//        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + MAPPER_PATH;
//        sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
//        //设置datasource
//        logger.info("设置datasource ============> "+druidDataSourceBuilder.dataSource());
//        sqlSessionFactoryBean.setDataSource(druidDataSourceBuilder.dataSource());
//        return sqlSessionFactoryBean;
//    }
///*
//
//    private DataSource dataSource() {
//        logger.info("maxWait - {}",maxWait);
//        Map<String,Object> properties=new HashMap<>();
//        properties.put(DruidDataSourceFactory.PROP_DRIVERCLASSNAME,driverClassName);
//        properties.put(DruidDataSourceFactory.PROP_URL,dbUrl);
//        properties.put(DruidDataSourceFactory.PROP_USERNAME,userName);
//        properties.put(DruidDataSourceFactory.PROP_PASSWORD,password);
//        properties.put(DruidDataSourceFactory.PROP_MAXWAIT,maxWait);
//        //添加统计、SQL注入、日志过滤器
//       // properties.put(DruidDataSourceFactory.PROP_FILTERS,"stat,wall,log4j2");
//        //sql合并，慢查询定义为5s
//        properties.put(DruidDataSourceFactory.PROP_CONNECTIONPROPERTIES,"druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000");
//        try {
//            return DruidDataSourceFactory.createDataSource(properties);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//*/
//
//}